//
//  DDCompanyImageCell.m
//  DingDongZP
//
//  Created by weily on 16/4/24.
//  Copyright © 2016年 iyhjiang.com. All rights reserved.
//

#import "DDCompanyImageCell.h"

@implementation DDCompanyImageCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)prepareForReuse
{
    [_bgImageView removeFromSuperview];
    [_replaceBtn removeFromSuperview];
    _infoLab.text = nil;
}

- (void)setImageWithURL:(NSString *)url {
    if (url.length > 0) {
        _bgImageView = [[UIImageView alloc] initWithFrame:self.bounds];
        [self.contentView addSubview:_bgImageView];
        [_bgImageView sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:nil];
        
        _replaceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _replaceBtn.backgroundColor = [UIColor blackColor];
        _replaceBtn.alpha = 0.6;
        _replaceBtn.layer.masksToBounds = YES;
        _replaceBtn.layer.cornerRadius = 15;
        _replaceBtn.layer.borderWidth = 1;
        _replaceBtn.layer.borderColor = [UIColor whiteColor].CGColor;
        [_replaceBtn setTitle:@"点击更换" forState:UIControlStateNormal];
        [_replaceBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _replaceBtn.titleLabel.font = [UIFont systemFontOfSize:15.0];
        _replaceBtn.frame = CGRectMake(0, 0, 85, 30);
        _replaceBtn.center = CGPointMake(self.width/2, self.height/2);
        __weak typeof(self) weakSelf = self;
        [_replaceBtn bk_addEventHandler:^(id sender) {
            if (weakSelf.replaceImage) {
                weakSelf.replaceImage(0);
            }
        } forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:_replaceBtn];
    }
}

- (void)setDescInfo:(NSString *)info {
    _infoLab.text = info;
}

- (void)setImageWithImage:(UIImage *)img {
    if (img) {
        _bgImageView = [[UIImageView alloc] initWithFrame:self.bounds];
        [self.contentView addSubview:_bgImageView];
        _bgImageView.image = img;
        _replaceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _replaceBtn.backgroundColor = [UIColor blackColor];
        _replaceBtn.alpha = 0.6;
        _replaceBtn.layer.masksToBounds = YES;
        _replaceBtn.layer.cornerRadius = 15;
        _replaceBtn.layer.borderWidth = 1;
        _replaceBtn.layer.borderColor = [UIColor whiteColor].CGColor;
        [_replaceBtn setTitle:@"点击更换" forState:UIControlStateNormal];
        [_replaceBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _replaceBtn.titleLabel.font = [UIFont systemFontOfSize:15.0];
        _replaceBtn.frame = CGRectMake(0, 0, 85, 30);
        _replaceBtn.center = CGPointMake(self.width/2, self.height/2);
        [self.contentView addSubview:_replaceBtn];
    }
}

@end
